package com.work.blog.model;

import com.work.blog.enums.ResultStatus;
import lombok.Data;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:DELL
 * Date:2025-06-16
 * Time:16:00
 */
@Data
public class Result<T> {
    //业务码200-成功 -1失败 -2未登录
    private ResultStatus code;//枚举类型
    //错误信息
    private String errMsg;
    //接口响应的数据
    private T data;
    //成功时候返回
    public static <T> Result<T> success(T data){
        Result result =new Result();
        result.setCode(ResultStatus.SUCCESS);
        result.setErrMsg("");
        result.setData(data);
        return result;
    }

    //失败--传递错误信息
    public static <T> Result<T> fail(String errMsg){
        Result result =new Result();
        result.setCode(ResultStatus.FAIL);
        result.setErrMsg(errMsg);
        result.setData(null);
        return result;
    }

    //失败时有数据返回--密码为空。。。
    public static <T> Result<T> fail(String errMsg,T data){
        Result result =new Result();
        result.setCode(ResultStatus.FAIL);
        result.setErrMsg(errMsg);
        result.setData(data);
        return result;
    }
}
